<?php

namespace Platform\Models\Video;

use Platform\Models\BaseModel;

class VideoViewLog extends BaseModel {

    const TABLE_NAME = 'video_view_log';

    public function initialize() {
        parent::initialize();
        $this->setSource(self::TABLE_NAME);
    }

    private $id;
    private $videoId;
    private $userId;
    private $createTime;

    public function getId() {
        return $this->id;
    }

    public function getVideoId() {
        return $this->videoId;
    }

    public function getUserId() {
        return $this->userId;
    }

    public function getCreateTime() {
        return $this->createTime;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function setVideoId($videoId) {
        $this->videoId = $videoId;
    }

    public function setUserId($userId) {
        $this->userId = $userId;
    }

    public function setCreateTime($createTime) {
        $this->createTime = $createTime;
    }

    public function columnMap() {
        //列名 =》 属性名
        return [
            'id' => 'id',
            'video_id' => 'videoId',
            'user_id' => 'userId',
            'create_time' => 'createTime',
        ];
    }

    /**
     * 根据视频ID以及用户ID获取浏览记录
     * @param type $phone
     */
    public function getDataByVideoIdAndUserId($videoId, $userId) {
        $query = [
            "conditions" => "videoId = :videoId: and userId = :userId:",
            "bind" => [
                "videoId" => $videoId,
                "userId" => $userId
            ],
        ];
        $data = self::findFirst($query);
        if ($data) {
            $data = $data->toArray();
        }
        return $data;
    }

}
